﻿using System;
using UnityEngine;

namespace MassiveBattle.Controller
{
	public abstract partial class BaseController : MonoBehaviour, Manager.IWorker
	{
		protected void SetDamagePoint(Action damagePointSetFunction)
		{
			if (TargetList == null)
				return;

			PointDic.Clear();

			if (damagePointSetFunction != null)
				damagePointSetFunction();
		}

		protected System.Action damagePointSetFunction;

		/// <summary>
		/// 모든 대상에게 100%만큼의 피해.
		/// </summary>
		protected void SetDamagePoint_Attack_A()
		{
			foreach (var target in TargetList)
				PointDic.Add(target, Utility.GetDamagePoint(Manager, Stat, target.Stat));
		}

		/// <summary>
		/// 기준이 되는 대상에게 100%만큼의 피해. 나머지에 80%만큼 피해.
		/// </summary>
		protected void SetDamagePoint_Attack_B()
		{
			PointDic.Add(TargetList[0], Utility.GetDamagePoint(Manager, Stat, TargetList[0].Stat));
			for (int i = 1; i < TargetList.Count; i++)
				PointDic.Add(TargetList[i], Mathf.FloorToInt(Utility.GetDamagePoint(Manager, Stat, TargetList[i].Stat) * 0.8f));
		}

		/// <summary>
		/// 모든 대상에게 100%만큼의 피해.
		/// </summary>
		protected void SetDamagePoint_Skill_A()
		{
			foreach (var target in TargetList)
				PointDic.Add(target, Mathf.FloorToInt(Utility.GetDamagePoint(Manager, Stat, target.Stat) * SkillData.skillMod));
		}

		/// <summary>
		/// 공격 테이크 재생 [시전자].
		/// </summary>
		protected void PlayTake_Attack_Source()
		{
			PlayTake(EMassTake.attack01, new[] { ModelGameObject, null });
		}

		/// <summary>
		/// 공격 테이크 재생 [시전자, 대상].
		/// </summary>
		protected void PlayTake_Attack_Source_Target()
		{
			PlayTake(EMassTake.attack01, new[] { ModelGameObject, Target.ModelGameObject }, area: Target.Area);
		}

		/// <summary>
		/// 스킬 테이크 재생 [시전자].
		/// </summary>
		protected void PlayTake_Skill_Source()
		{
			PlayTake(EMassTake.skill01, new[] { ModelGameObject });
		}

		protected void PlayTake_Skill_Source_Target_Null()
		{
			PlayTake(EMassTake.skill01, new[] { ModelGameObject, Target.ModelGameObject, null });
		}

		/// <summary>
		/// 스킬 테이크 재생 [시전자, 대상, 카메라].
		/// </summary>
		protected void PlayTake_Skill_Source_Target_Camera()
		{
			PlayTake(EMassTake.skill01, new[] { ModelGameObject, Target.ModelGameObject, EventlineStaticActor.Camera });
		}

		protected void PlayTake_Skill_Source_Target_Start_End()
		{
			PlayTake(EMassTake.skill01, new[] { ModelGameObject, Target.ModelGameObject, null, null });
		}

		protected void AttachCamera_Skill_A()
		{
			if (EventlineStaticActor.Camera != null)
			{
				if (UnityEngine.Random.value < 0.25f && EventlineStaticActor.Camera.transform.parent == null)
				{
					Manager.StopTake();

					EventlineStaticActor.Camera.transform.parent = pointCamera;
					EventlineStaticActor.Camera.transform.localPosition = Vector3.zero;
					EventlineStaticActor.Camera.transform.localRotation = Quaternion.identity;
				}
			}
		}

		protected void AttachCamera_Skill_B()
		{
			if (EventlineStaticActor.Camera != null)
			{
				Manager.StopTake();

				EventlineStaticActor.Camera.transform.parent = pointCamera;
				EventlineStaticActor.Camera.transform.localPosition = Vector3.zero;
				EventlineStaticActor.Camera.transform.localRotation = Quaternion.identity;
			}
		}
	}
}